﻿<ContentControl x:Class="Microsoft.VisualStudio.TestTools.WorkItemMigrator.SelectDataSourceView"
                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:WorkItemMigrator="clr-namespace:Microsoft.VisualStudio.TestTools.WorkItemMigrator"
                xmlns:sys="clr-namespace:System;assembly=mscorlib"
                Margin="7"
                x:ClassModifier="internal">
    <ContentControl.Resources>
        <WorkItemMigrator:StringToVisibilityConverter x:Key="StringToVisibilityConverter" />
        <WorkItemMigrator:InverseBooleanConverter x:Key="InverseBooleanConverter" />
        <WorkItemMigrator:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
        <WorkItemMigrator:InverseBooleanToVisibilityConverter x:Key="InverseBooleanToVisibilityConverter" />

    </ContentControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <Grid Grid.Row="0"
              Margin="0,0,0,10">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>

            <TextBlock x:Uid="SelectDataSourceLabel"
                       Text="Select Data Source Type:"
                       Grid.Column="0"
                       VerticalAlignment="Center" />

            <ComboBox x:Uid="DataSourceComboBox"
                      VerticalAlignment="Center"
                      Margin="10,0,0,0"
                      Grid.Column="1"
                      ItemsSource="{Binding DataSources}"
                      SelectedItem="{Binding SelectedDataSource}" />

        </Grid>


        <!-- MHT Data Source -->
        <Grid Grid.Row="1">
            <Grid.Style>
                <Style TargetType="{x:Type Grid}">
                    <Setter Property="Visibility" Value="Collapsed" />
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding DataSourceType}"
                                     Value="{x:Static WorkItemMigrator:DataSourceType.MHT}">
                            <Setter Property="Visibility" Value="Visible" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Grid.Style>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <RadioButton x:Uid="MHTFolderRadioButton"
                             IsChecked="{Binding IsMHTFolder}"
                             Grid.Row="0"
                             Margin="0,12,0,0"
                             GroupName="MHTInputSelection">
                Select folder containing mht/word files:
            </RadioButton>
            <!-- ====== Input MHT Folder Box and Browse ========= -->
            <Grid Grid.Row="1"
                      IsEnabled="{Binding IsMHTFolder}"
                      Margin="15,7,0,0">
                <Grid.ColumnDefinitions>

                    <!-- Input File Box -->
                    <ColumnDefinition Width="*" />

                    <!-- Browse Button -->
                    <ColumnDefinition Width="Auto" />

                </Grid.ColumnDefinitions>

                <!-- ==== Input File Box ==== -->
                <WorkItemMigrator:WITMigratorTextBox x:Name="MHTFolderPathTextBox" 
                                                     Grid.Column="0"
                                                     x:Uid="SelectDataSource.MHTFolderPath"
                                                     AutomationProperties.AutomationId="SelectDataSource.MHTFolderPath"
                                                     AutomationProperties.Name="MHTFolderPath"
                                                     IsReadOnly="False"
                                                     Text="{Binding MHTFolderPath}" 
                                                     IsRequired="{Binding RelativeSource={RelativeSource Self}, Path=IsEnabled}"
                                                     TextChangeAction="MHTFolderPath_TextChangeAction" />

                <!-- ==== Browse Button ==== -->
                <Button Grid.Column="1"
                            Margin="10,0,0,0"
                            x:Uid="SelectDataSource.MHTFolderBrowseButton"
                            AutomationProperties.AutomationId="SelectDataSource.MHTFolderBrowseButton"
                            AutomationProperties.Name="MHTFolderBrowseButton"
                            x:Name="MHTFolderBrowseButton"
                            Content="_..."
                            Click="MHTFolderBrowse_Click" />
            </Grid>

            <Grid Grid.Row="2"
                  Margin="0,3,0,0"
                  Visibility="{Binding IsMHTFolder, Converter={StaticResource BooleanToVisibilityConverter}}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <TextBlock Grid.Column="0"
                           Text="Loading..."
                           Visibility="{Binding IsLoadingFiles, Converter={StaticResource BooleanToVisibilityConverter}}" />
                <TextBlock Grid.Column="1">
                    <TextBlock.Text>
                        <Binding Path="MHTCount"
                                 StringFormat="{}{0} documents found." />                    
                    </TextBlock.Text>
                </TextBlock>
            </Grid>


            <RadioButton x:Uid="ListOfMHTsFilePathRadioButton"
                             IsChecked="{Binding IsMHTFolder, Converter={StaticResource InverseBooleanConverter}}"
                             Grid.Row="3"
                             Margin="0,12,0,0"
                             GroupName="MHTInputSelection">
                Select text file containing list of mht/word files with full path:
            </RadioButton>
            <!-- ====== Input MHT Folder Box and Browse ========= -->
            <Grid Grid.Row="4"
                      IsEnabled="{Binding IsMHTFolder, Converter={StaticResource InverseBooleanConverter}}"
                      Margin="15,7,0,0">
                <Grid.ColumnDefinitions>

                    <!-- Input File Box -->
                    <ColumnDefinition Width="*" />

                    <!-- Browse Button -->
                    <ColumnDefinition Width="Auto" />

                </Grid.ColumnDefinitions>

                <!-- ==== Input File Box ==== -->
                <WorkItemMigrator:WITMigratorTextBox x:Name="ListOfMHTsFilePath" 
                                                     Grid.Column="0"
                                                     x:Uid="SelectDataSource.ListOfMHTsFilePath"
                                                     AutomationProperties.AutomationId="SelectDataSource.ListOfMHTsFilePath"
                                                     AutomationProperties.Name="ListOfMHTsFilePath"
                                                     IsReadOnly="False"
                                                     Text="{Binding ListOfMHTsFilePath}" 
                                                     IsRequired="{Binding RelativeSource={RelativeSource Self}, Path=IsEnabled}"
                                                     TextChangeAction="ListOfMHTsFilePath_TextChangeAction" />

                <!-- ==== Browse Button ==== -->
                <Button Grid.Column="1"
                            Margin="15,0,0,0"
                            x:Uid="SelectDataSource.ListOfMHTsFilePathBrowseButton"
                            AutomationProperties.AutomationId="SelectDataSource.ListOfMHTsFilePathBrowseButton"
                            AutomationProperties.Name="ListOfMHTsFilePathBrowseButton"
                            x:Name="ListOfMHTsFilePathBrowseButton"
                            Content="_..."
                            Click="ListOfMHTsFilePathBrowse_Click" />
            </Grid>
            <Grid Grid.Row="5"
                  Margin="0,3,0,0"
                  Visibility="{Binding IsMHTFolder, Converter={StaticResource InverseBooleanToVisibilityConverter}}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <TextBlock Grid.Column="0"
                           Text="Loading..."
                           Visibility="{Binding IsLoadingFiles, Converter={StaticResource BooleanToVisibilityConverter}}" />
                <TextBlock Grid.Column="1">
                    <TextBlock.Text>
                        <Binding Path="MHTCount"
                                 StringFormat="{}{0} documents found." />                    
                    </TextBlock.Text>
                </TextBlock>
            </Grid>
        </Grid>



        <!-- Excel Data Source -->
        <Grid Grid.Row="1">
            <Grid.Style>
                <Style TargetType="{x:Type Grid}">
                    <Setter Property="Visibility" Value="Collapsed" />
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding DataSourceType}"
                                     Value="{x:Static WorkItemMigrator:DataSourceType.Excel}">
                            <Setter Property="Visibility" Value="Visible" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Grid.Style>
            <Grid.RowDefinitions>

                <!-- Data Source File -->
                <RowDefinition Height="Auto" />

                <!-- Data Source WorkSheet -->
                <RowDefinition Height="Auto" />

                <!-- Preview -->
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>

            <!-- ====================================== Data Source Information =================================== -->
            <Grid Grid.Row="0"
              Margin="0,0,10,0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="18" />
                </Grid.RowDefinitions>


                <!-- ====== Input File Path label ========= -->
                <TextBlock x:Uid="SelectDataSource.ExcelFilePathLabel"      
                       Grid.Row="0"  
                       Margin="0,5,0,0"                       
                       Text="Specify file path for excel workbook:" />


                <!-- ====== Input File Box and Browse ========= -->
                <Grid Grid.Row="1"
                          Margin="0,7,0,0">
                    <Grid.ColumnDefinitions>

                        <!-- Input File Box -->
                        <ColumnDefinition Width="*" />

                        <!-- Browse Button -->
                        <ColumnDefinition Width="Auto" />

                    </Grid.ColumnDefinitions>

                    <!-- ==== Input File Box ==== -->


                    <WorkItemMigrator:WITMigratorTextBox x:Name="ExcelFileName" 
                                 Grid.Column="0"
                                 x:Uid="SelectDataSource.ExcelFileTextBox"
                                 AutomationProperties.AutomationId="SelectDataSource.ExcelFileTextBox"
                                 AutomationProperties.Name="ExcelFileTextBox"
                                 IsReadOnly="False"
                                 Text="{Binding ExcelFilePath}"
                                 TextChangeAction="ExcelFileName_TextChangeAction"
                                 IsRequired="True" />
                        

                    <!-- ==== Browse Button ==== -->
                    <Button Grid.Column="1"
                        Margin="10,0,0,0"
                        x:Uid="SelectDataSource.ExcelSourceFileBrowseButton"
                        AutomationProperties.AutomationId="SelectDataSource.ExcelSourceFileBrowseButton"
                        AutomationProperties.Name="ExcelSourceFileBrowseButton"
                            x:Name="ExcelSourceFileBrowseButton"
                        Content="_..."
                        Click="ExcelFileBrowse_Click" />
                </Grid>

                <TextBlock Grid.Row="2"
                       Margin="0,3,0,0"
                       Visibility="{Binding ExcelFilePath, Converter={StaticResource StringToVisibilityConverter}}">
                    <TextBlock.Text>
                        <Binding Path="ExcelSheetsCount"
                                 StringFormat="{}{0} worksheets found." />                    
                    </TextBlock.Text>
                </TextBlock>
            </Grid>


            <!-- ======================================== Data Source Load Settings ===================================== -->
            <Grid Margin="0,10,30,0"
              Grid.Row="1">
                <Grid.RowDefinitions>

                    <!-- Excel Worksheet Label -->
                    <RowDefinition Height="Auto" />

                    <!-- Excel Worksheets ComboBox -->
                    <RowDefinition Height="Auto" />

                    <!-- Excel Header Row -->
                    <RowDefinition Height="Auto" />

                </Grid.RowDefinitions>



                <!-- ====== Excel Worksheet Label ========= -->
                <TextBlock x:Uid="SelectDataSource.ExcelWorkSeet"
                           Grid.Row="0"
                           Margin="0,7,0,0"
                           Text="Select the worksheet to migrate:" />


                <!-- ====== Excel Worksheets ComboBox ========= -->
                <ComboBox x:Name="ExcelSheets" 
                          Grid.Row="1"
                          ItemsSource="{Binding ExcelSheets}"
                          SelectedItem="{Binding SelectedExcelSheet}"
                          Margin="0,7,26,0"
                          AutomationProperties.AutomationId="SelectDataSource.ExcelSheets"
                          AutomationProperties.Name="ExcelSheets" />


                <!-- ====== Excel Column Name Information ========= -->
                <Grid Grid.Row="2"
                  Margin="0,15,0,0">

                    <Grid.ColumnDefinitions>

                        <!-- Excel Column Name Label -->
                        <ColumnDefinition Width="Auto" />

                        <!-- Excel Column Name TextBox -->
                        <ColumnDefinition Width="Auto" />

                    </Grid.ColumnDefinitions>

                    <!-- ==== Excel Column Name Label ==== -->
                    <TextBlock Text="Enter row number that has field names:"
                           Grid.Column="0"
                           VerticalAlignment="Center"
                           x:Uid="SelectDataSource.EnterRow" />

                    <!-- ==== Excel Column Name TextBox ==== -->
                    <WorkItemMigrator:WITMigratorTextBox x:Name="ExcelHeaderRow"
                                                         Grid.Column="1" 
                                                         AutomationProperties.AutomationId="SelectDataSource.ExcelHeaderRowTextBox"
                                                         AutomationProperties.Name="ExcelHeaderRowTextBox"
                                                         Text="{Binding ExcelHeaderRow, UpdateSourceTrigger=PropertyChanged}"
                                                         VerticalAlignment="Center"
                                                         Margin="10,0,0,0"
                                                         Width="70"
                                                         IsRequired="True"
                                                         TextChangeAction="ExcelHeaderRow_TextChangeAction"/>
                </Grid>
            </Grid>

            <!-- ======================================== Preview Data Source File ===================================== -->
            <Grid Grid.Row="2"
              Margin="0,10,0,0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <TextBlock Text="Preview:"
                       Grid.Row="0"
                       Grid.Column="0" />
                <Image Height="16"
                   Width="16"
                   Grid.Row="0"
                   Grid.Column="1"
                   VerticalAlignment="Center"
                   Margin="0,0,3,0"
                   Source="{DynamicResource Excel_32}" />
                <TextBlock Grid.Row="0"
                       Grid.Column="2">
                <Hyperlink Click="Preview_Click"
                           IsEnabled="{Binding IsPreviewEnabled}"
                           AutomationProperties.AutomationId="SelectDataSource.PreviewButton"
                           AutomationProperties.Name="PreviewButton"
                           x:Uid="SelectDataSource.PreviewButton">
                    Open file
                    <Hyperlink.Style>
                        <Style TargetType="{x:Type Hyperlink}">
                            <Setter Property="Foreground" 
                                    Value="{DynamicResource HyperLinkBrush}" />
                            <Style.Triggers>
                                <Trigger Property="IsEnabled"
                                         Value="false">
                                    <Setter Property="Foreground"
                                            Value="Gray" />                                    
                                </Trigger>                                
                            </Style.Triggers>
                        </Style>
                    </Hyperlink.Style>
                </Hyperlink>
                </TextBlock>

                <DataGrid ItemsSource="{Binding Fields}"
                      x:Name="ColumnMappingControl"
                      Margin="0,5,0,0"
                      ScrollViewer.VerticalScrollBarVisibility="Auto"
                      AutoGenerateColumns="False"
                      GridLinesVisibility="None"
                      CanUserAddRows="False"
                      CanUserDeleteRows="False"
                      CanUserResizeRows="False"
                      CanUserReorderColumns="False"
                      CanUserSortColumns="False"
                      Grid.Row="1"
                      Grid.ColumnSpan="3">
                    <DataGrid.Columns>
                        <DataGridTextColumn Header="Field Names"
                                        HeaderStyle="{DynamicResource DataGridHeaderTextStyle}"
                                        Width="*"
                                        Binding="{Binding}" />
                    </DataGrid.Columns>
                </DataGrid>
            </Grid>
        </Grid>
    </Grid>
</ContentControl>